/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.group4.highschoolportal.parent.backingBean;

import com.group4.entity.Course;
import com.group4.entity.Grade;
import com.group4.entity.Lesson;
import com.group4.entity.Parent;

import com.group4.entity.Student;
import com.group4.highschoolportal.loginBean.IndexBackingBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Victor Cernea
 */
@ManagedBean
@SessionScoped
public class ParentBackingBean implements Serializable {

    private Parent parent;
    private List<Course> courses;
    private List<Student> children;
    private List<Lesson> lessons;
    private List<Grade> grades;
    
    /** Creates a new instance of StudentBackingBean */
    public ParentBackingBean() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        parent = (Parent) session.getAttribute("user");
        courses = new ArrayList<Course>();
        children = new ArrayList<Student>();
        lessons = new ArrayList<Lesson>();
        grades = new ArrayList<Grade>();
    }

    @PostConstruct
    private void init() {
         
        children = parent.getChildren();
        for (Student s : children) {
            for (Course c : s.getsCourses()) {
                courses.add(c);
            }
            for (Grade g : s.getGrades()) {
                grades.add(g);
            }
        }
        for (Course c : courses) {
            for (Lesson l : c.getLesson()) {
                lessons.add(l);
            }
        }
        
    }

    public Parent getParent() {
        return parent;
    }

    public void setParent(Parent parent) {
        this.parent = parent;
    }

    public List<Course> getCourses() {
        return courses;
    }

    public void setCourses(List<Course> courses) {
        this.courses = courses;
    }

    public List<Student> getChildren() {
        return children;
    }

    public void setChildren(List<Student> children) {
        this.children = children;
    }

    public List<Lesson> getLessons() {
        return lessons;
    }

    public void setLessons(List<Lesson> lessons) {
        this.lessons = lessons;
    }

    public List<Grade> getGrades() {
        return grades;
    }

    public void setGrades(List<Grade> grades) {
        this.grades = grades;
    }
    
}
